#! groovy
import hudson.EnvVars
import hudson.model.*

node{

    def	GIT_URL="git@10.28.151.136:tpbb/tpbb-e-manager-service.git"
    def SERVER_IP="10.26.196.15"
    def SERVER_USR="tpbbops"
    def REMOTE_DIR="/data/jars/e-manager-service"
    def DEPLOY_DIR="~/e-manager-service"
    def R_DIR="src/main/resources"
    def R_FILE="application-prod.properties"

    stage('\u27BD Checkout SCM'){
        git(url:"$GIT_URL",branch:"${BRANCH}")
    }
    stage('\u27BD Build'){
        sh "mvn clean package -P prod -Dmaven.test.skip"
    }
    stage('\u27BD Deploy to SERVER'){
        def pom =readMavenPom file:'pom.xml'
        jarName="${pom.build.finalName}"?:"${pom.artifactId}"
        sh "cd target&&cp ../${R_DIR}/${R_FILE} .&&tar cvf ${jarName}.tar ${jarName}.jar"
        sh "scp target/${jarName}.tar $SERVER_USR@$SERVER_IP:$REMOTE_DIR"
        sh "ssh $SERVER_USR@$SERVER_IP 'cd $REMOTE_DIR&&cp ${jarName}.tar ${jarName}.tar.${BUILD_ID}'"
    }
}

